﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Public;
using BUS;
using System.IO;

namespace QuanLyKhoHangVatTu
{
    public partial class QuanLyNguoiDung : DevExpress.XtraEditors.XtraForm
    {
        TaiKhoan_BUS tk_bus = new TaiKhoan_BUS();
        TaiKhoan_PB tk_pb = new TaiKhoan_PB();
        Flag_PB flag_pb = new Flag_PB();
        public static Image myImage;

        public QuanLyNguoiDung()
        {
            InitializeComponent();
        }

        private void QuanLyNguoiDung_Load(object sender, EventArgs e)
        {
            Flag_PB.Flag = 10;
            gridQLND.DataSource = tk_bus.LayDSTaiKhoan();
        }

        #region "Chuyển byte thành img"
        public Image ByteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
        #endregion


        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridView1.DataRowCount > 0)
            {
                TaiKhoan_PB.TenTaiKhoan = gridView1.GetRowCellValue(e.FocusedRowHandle, "TENDANGNHAP").ToString();
                TaiKhoan_PB.MatKhau = gridView1.GetRowCellValue(e.FocusedRowHandle, "MATKHAU").ToString();
                TaiKhoan_PB.HoTen = gridView1.GetRowCellValue(e.FocusedRowHandle, "HOTEN").ToString();
                TaiKhoan_PB.DonVi = gridView1.GetRowCellValue(e.FocusedRowHandle, "DONVI").ToString();
                TaiKhoan_PB.Email = gridView1.GetRowCellValue(e.FocusedRowHandle, "EMAIL").ToString();

                try
                {
                    myImage = ByteArrayToImage((byte[])gridView1.GetRowCellValue(e.FocusedRowHandle, "HINHANH"));
                }
                catch
                { }
            }
        }
    }
}